{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Amazon Personalize\n",
    "\n",
    "Amazon Personalize is a machine learning service that makes it easy for developers to add individualized recommendations to customers who use their applications. It reflects the vast experience that Amazon has in building personalization systems.\n",
    "\n",
    "You can use Amazon Personalize in a variety of scenarios, such as giving users recommendations based on their preferences and behavior, personalized re-ranking of results, and personalizing content for emails and notifications."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import boto3\n",
    "import sagemaker\n",
    "import pandas as pd\n",
    "\n",
    "sess   = sagemaker.Session()\n",
    "bucket = sess.default_bucket()\n",
    "role = sagemaker.get_execution_role()\n",
    "region = boto3.Session().region_name\n",
    "\n",
    "from botocore.config import Config\n",
    "\n",
    "config = Config(\n",
    "   retries = {\n",
    "      'max_attempts': 10,\n",
    "      'mode': 'adaptive'\n",
    "   }\n",
    ")\n",
    "\n",
    "personalize = boto3.Session().client(service_name='personalize-runtime', region_name=region)\n",
    "account_id = boto3.client('sts').get_caller_identity().get('Account')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Items Schema\n",
    "```\n",
    "{\n",
    "\t\"type\": \"record\",\n",
    "\t\"name\": \"Items\",\n",
    "\t\"namespace\": \"com.amazonaws.personalize.schema\",\n",
    "\t\"fields\": [\n",
    "\t\t{\n",
    "\t\t\t\"name\": \"ITEM_ID\",\n",
    "\t\t\t\"type\": \"string\"\n",
    "\t\t},\n",
    "\t\t{\n",
    "\t\t\t\"name\": \"PRODUCT_TITLE\",\n",
    "\t\t\t\"type\": \"string\",\n",
    "      \"categorical\": false\n",
    " \t\t\t\n",
    "\t\t},\n",
    "\t\t{\n",
    "\t\t\t\"name\": \"PRODUCT_CATEGORY\",\n",
    "\t\t\t\"type\": \"string\",\n",
    "      \"categorical\": true\n",
    "\t\t}\n",
    "\t],\n",
    "\t\"version\": \"1.0\"\n",
    "}```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "personalize_campaign_name = 'amazon-reviews-campaign'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "response = personalize.get_recommendations(\n",
    "    campaignArn='arn:aws:personalize:{}:{}:campaign/{}'.format(region, account_id, personalize_campaign_name),\n",
    "    itemId='B00U7LCE6A',\n",
    "    numResults=10\n",
    ")\n",
    "\n",
    "response['itemList']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# TODO:  Retrieve Item Titles"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%javascript\n",
    "Jupyter.notebook.save_checkpoint();\n",
    "Jupyter.notebook.session.delete();"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda_python3",
   "language": "python",
   "name": "conda_python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
